import { JKManager } from "../JKManager";
import { LocalizedLabel } from "../Language/LocalizedLabel";

const { ccclass, property } = cc._decorator;


@ccclass
export class UnunitedCpnt extends cc.Component {

    // @property({ displayName: '打开速度' })
    // openDuration: number = 0.2;

    // @property({ displayName: '关闭速度' })
    // closeDuration: number = 0.2;
    public _callback: Function = null;
    btReconnece: cc.Node;

    onLoad(): void {
        cc.log(`${cc.js.getClassName(this)} onLoad`)
        this.btReconnece = this.node.getChildByName(`btReconnece`);
        this.btReconnece.on(cc.Node.EventType.TOUCH_END, this.onBtReconnece, this);
    }

    onDestroy() {
        this._callback = null;
        this.btReconnece.off(cc.Node.EventType.TOUCH_END, this.onBtReconnece, this);
    }


    /**
     * 显示
     */
    show(callback: () => void = null) {
        this._callback = callback;
        cc.log(`${cc.js.getClassName(this)} show`)
        this.node.active = true;
    }

    /**
     * 隐藏
     */
    hide(): void {
        cc.log(`${cc.js.getClassName(this)} hide`)
        this.node.active = false;
    }

    onBtReconnece() {
        this.hide();
        if (this._callback) this._callback();
    }
}